<?php
require_once(ROOT_ADMIN_MODELS.DS.'Models_User.php');
require_once(ROOT_ADMIN_MODELS.DS.'Models_Group.php');
require_once(ROOT_ADMIN_MODELS.DS.'Models_Base.php'); 
require_once(ROOT_ADMIN_OBJECT.DS.'Objs_User.php');
require_once(ROOT_ADMIN_MODELS.DS.'Models_Log.php'); 
require_once(ROOT_LIBRARY_UTILITY.DS.'utility.php');
require_once(ROOT_ADMIN_FORMS.DS.'Forms_User.php');
require_once(ROOT_ADMIN_CONTROLLERS.DS.'BaseController.php');
class Admin_UserController extends BaseController {
	
	public function preDispatch()
	{
		parent::preDispatch();	
		if(!$this->hasPrivilege())
			$this->_redirect ("/admin/error/permission");
	}
			
	public function indexAction()
	{
		try 
		{	
			$baseurl=$this->_request->getbaseurl();		
			$this->view ->headTitle("UIT-News Supporter");		
			$request = $this->getRequest();
			$this->view->headMeta()->setHttpEquiv('Content-Type', 'text/html;charset=utf-8');
			$this->view->headMeta()->appendName('keywords', 'view,specific,keywords');
			//$a=$request->getControllerName();			
			//	echo $a;
			$this->view->headLink()->appendStylesheet($baseurl."/public/css/test.css");
			$md=new Model_User();
			$this->view->data=$md->listUser();	
			//Models_Log::insert("aa", "act_update_AwardItem","s");
		}
		catch(Exception $ex)
		{
			$this->view->errMsg = $ex->getMessage();
			Utility::log($ex->getMessage(), $ex->getFile(), $ex->getLine());
		} 
		
				
	
	}
	public function editAction()
	{
		try 
		{
			$this->view ->headTitle("UIT-News Supporter");
			$id=$this->_request->getParam('id');			
			$md=new Model_User();
			$mdgroup=new Model_Group();
			$this->view->group=$mdgroup->listGroup();
			if($this->_request->isPost())
			{										
				$form = new Forms_User();
				$form->_requestToForm($this);		
				$md->updateuser($form->obj);
				$this->view->msg="update thành công";
				$this->view->thisuser=$md->getUserbyID($id);
				Models_Log::insert($this->view->user->id, "act_update_user","id=".$id);
			}
			else
			{
				$this->view->thisuser=$md->getUserbyID($id);
			}
			
		}
		catch(Exception $ex)
		{
			echo($ex->getMessage());
			$this->view->errMsg = $ex->getMessage();
			Utility::log($ex->getMessage(), $ex->getFile(), $ex->getLine());
		}
	}
	
	public function activeAction()
	{
		try
		{
			$this->_helper->layout->disableLayout();
			$this->_helper->viewRenderer->setNorender();
			$id = $this->_request->getParam('id');
			$active = $this->_request->getParam('active');
			$md = new Model_User();
			
			$md->active($id, $active);
			Models_Log::insert($this->view->user->id, "act_update_status_user","id=".$id);
			echo "1";
		}
		catch(Exception $ex)
		{
			echo($ex->getMessage());
			$this->view->errMsg = $ex->getMessage();
			Utility::log($ex->getMessage(), $ex->getFile(), $ex->getLine());
		}
	} 
}